<?php

namespace backend\modules\personnel\controllers;

use common\models\base\SearchModel;
use common\models\personnel\ByProDetails;
use common\traits\Curd;
use Yii;
use backend\controllers\BaseController;

/**
 * Class ByProject
 * @package backend\modules\project\controllers
 */
class ByProDetailsController extends BaseController
{
    use Curd;

    public $modelClass = ByProDetails::class;

    /**
     * 首页
     * @return string
     */
    public function actionIndex(){
        $id = Yii::$app->request->get('id');
        $searchModel = new SearchModel([
            'model' => $this->modelClass,
            'scenario' => 'default',
            'partialMatchAttributes' => ['module','title'], // 模糊查询
            'defaultOrder' => [
                'id' => SORT_DESC
            ],
            'pageSize' => $this->pageSize
        ]);
        $dataProvider = $searchModel
            ->search(Yii::$app->request->queryParams);
        $dataProvider->query
            ->andwhere(['pro_id'=>$id]);
        return $this->render($this->action->id, [
            'dataProvider' => $dataProvider,
            'searchModel' => $searchModel,
            'li'=>$id,
            'name' => Yii::$app->services->menu->getGroup(),
        ]);
    }
    /**
     * 编辑/创建
     *
     * @return mixed
     */
    public function actionEdit()
    {
        $id = Yii::$app->request->get('id', null);
        $pro_id =Yii::$app->request->get('li');
        $model = $this->findModel($id);
        if($pro_id){
            $model->pro_id = $pro_id;
        }
        if ($model->load(Yii::$app->request->post()) && $model->save()) {
            return $this->referrer();
        }
        return $this->render($this->action->id, [
            'model' => $model,
            'menuDropDownList' => Yii::$app->services->menu->getGroup(),
        ]);
    }
}
